<?php
class Template {

    private $ID;
    private $template_name;
    private $template_value;

    public function getByID($ID) {
        $list = array();
        $sql = "SELECT * FROM caws_templates
                WHERE ID = '" . $ID . "' ";

        $result = mysql_query($sql);
        $i = 0;
        while($rows = mysql_fetch_array($result)) {
            $list[$i]['ID'] = $rows['ID'];
            $list[$i]['template_name'] = base64_decode($rows['template_name']);
            $list[$i]['template_value'] = base64_decode($rows['template_value']);
            $i++;
        }
        return $list;
    }

    public function getByObj(Template $t) {
        $list = array();
        $sql = 'SELECT * FROM caws_templates
                WHERE 1 ';

        $result = mysql_query($sql);
        $i = 0;
        while($rows = mysql_fetch_array($result)) {
            $list[$i]['ID'] = $rows['ID'];
            $list[$i]['template_name'] = $rows['template_name'];
            $list[$i]['template_value'] = $rows['template_value'];
            $i++;
        }
        return $list;
    }

    public function insertData(Template $i) {
        $sql = "INSERT INTO caws_templates
                (template_name , template_value)
                VALUES
                ('" . $i->template_name . "',
                 '" . $i->template_value . "') ";

        mysql_query($sql);
    }

    public function updateData(Template $t) {
        $sql = "UPDATE caws_templates SET
                template_name = '" . $t->getTemplateName() . "' ,
                template_value = '" . $t->getTemplateValue() . "'
                WHERE ID = '" . $t->getID() . "' ";
        mysql_query($sql);
    }

    public function deleteData($ID) {
        $sql = "DELETE FROM caws_templates WHERE ID = '" . $ID . "'";
        mysql_query($sql);
    }

    public function setID($ID) {
        $this->ID = $ID;
    }

    public function getID() {
        return $this->ID;
    }

    public function setTemplateName($templateName) {
        $this->template_name = $templateName;
    }

    public function getTemplateName() {
        return $this->template_name;
    }

    public function setTemplateValue($templateValue) {
        $this->template_value = $templateValue;
    }

    public function getTemplateValue() {
        return $this->template_value;
    }
}
?>
